package com.d0306.Z06;

public class Hero {
    int exp;
    int level;
    public Hero(){
        this(0);
    }
    public Hero(int exp){
        if(exp<0){
            this.exp=0;
            this.level=0;
        }else if(exp>getMaxExp()){
            this.exp=getMaxExp();
            this.level=getMaxLevel();
        }else{
            int level=0;
            while(exp-getExp(level+1)>=0){
                level++;
            }
            this.level=level;
            this.exp=exp;
        }
    }
    int getMaxExp(){
        return getExp(30);
    }
    int getMaxLevel(){
        return 30;
    }
    int getExp(int level){
        int getExp=30*(level*level*level+5*level)-80;
        return getExp;
    }

    public static void main(String[] args) {
        Hero hero=new Hero(170);//有参构造方法；
        System.out.println("英雄的等级为:"+hero.level);
        System.out.println("英雄的经验值为:"+hero.exp);
        Hero hero1=new Hero();//无参构造方法；
        System.out.println("英雄的等级为:"+hero1.level);
        System.out.println("英雄的经验值为:"+hero1.exp);
    }
}

